package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JScrollPane;
import javax.swing.JEditorPane;
import java.awt.Canvas;
import java.awt.TextArea;
import java.awt.ScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.table.DefaultTableModel;
import java.awt.TextField;
import javax.swing.JTextPane;
import javax.swing.JLayeredPane;
import javax.swing.JDesktopPane;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import java.awt.List;
import javax.swing.JLabel;
import java.awt.Font;
import java.util.ArrayList;

import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerAgendas;
import br.com.fafica.sisape.model.AgendaConsulta;
import br.com.fafica.sisape.model.AgendaExame;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TelaClinicaAgendaExames extends JFrame {

	private JPanel contentPane;
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaMedicoListarPaciente frame = new TelaMedicoListarPaciente();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaClinicaAgendaExames() {
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 600, 400);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 56, 574, 257);
		contentPane.add(scrollPane);
		
		table = new JTable();
		table.setFont(new Font("Tahoma", Font.PLAIN, 12));
		table.setForeground(new Color(0, 0, 128));
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"New column", "New column"
			}
		));
		scrollPane.setViewportView(table);
		carregaTabela();
		
		JLabel lblPacintes = new JLabel("Exames Agendados");
		lblPacintes.setForeground(new Color(0, 0, 128));
		lblPacintes.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblPacintes.setBounds(10, 11, 151, 28);
		contentPane.add(lblPacintes);
		
		JButton btnSair = new JButton("Sair");
		btnSair.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		btnSair.setForeground(new Color(0, 0, 128));
		btnSair.setFont(new Font("Tahoma", Font.PLAIN, 12));
		btnSair.setBounds(448, 326, 136, 25);
		contentPane.add(btnSair);
	}
	
	public void carregaTabela() {

		ControllerAgendas controlUser = new ControllerAgendas();
		ArrayList<AgendaExame> listaExame = new ArrayList<AgendaExame>();

		listaExame = controlUser.listarAgendaExame();
		AgendaExame ag;

		DefaultTableModel modelo = new DefaultTableModel();

		// Adicionando Colunas
		modelo.addColumn("Data:");
		modelo.addColumn("Hora:");
		modelo.addColumn("Nome:");

		if (listaExame.size() == 0) {
			modelo.addRow(new String[] { "Sem dados", null, null });
		}
		// Percorrendo um array list e adicionando linhas
		for (int i = 0; i < listaExame.size(); i++) {
			ag = listaExame.get(i);

			modelo.addRow(new String[] { ag.getData().toString(), ag.getHora(),
					ag.getNome()});
		}
		table.setModel(modelo);
		table.getColumnModel().getColumn(0).setPreferredWidth(30);
		table.getColumnModel().getColumn(1).setPreferredWidth(30);
		table.getColumnModel().getColumn(2).setPreferredWidth(100);
	}
}
